package com.bk.web.controller;

import com.bk.controller.BKNormalController;
import com.moomi.common.model.BkShop;
import com.moomi.common.model.BkUser;
import com.moomi.common.model.BkUserShop;
import com.utils.SHA1;

public class BKWebHomeController extends BKNormalController {
	public void index() {
		render("index.html");
	}

	public void register() {
		render("register.html");
	}

	public void add() {
		BkUser user = new BkUser();
		user.setPassword("123");
		user.setEmail("123@123");
		user.save();

		BkShop shop = new BkShop();
		shop.setName("新的店铺");
		shop.save();

		BkUserShop userShop = new BkUserShop();
		userShop.setUserId(user.getId());
		userShop.setShopId(shop.getId());
		userShop.save();
	}

	public void confirmRegister() {
		BkUser model = getModel(BkUser.class);
		String confirmPassword = getPara("confirmPassword");
		if (!confirmPassword.equals(model.getPassword())) {
			renderText("密码不匹配");
			renderJson(model);
		} else {
			boolean registerFlag = model.save();
			System.out.println("registerFlag " + registerFlag);
			String hash = "CJWBooking" + model.getId();
			model.setHash(SHA1.getSha1(hash));
			model.update();
			String email = model.getEmail();

			BkShop shop = new BkShop();
			shop.setName("新的店铺");
			shop.save();

			BkUserShop userShop = new BkUserShop();
			userShop.setUserId(model.getId());
			userShop.setShopId(shop.getId());
			userShop.save();

			// BkItem item = new BkItem();
			// item.setName("预约项目");
			// item.save();
			//
			// BkSelection selection = new BkSelection();
			// selection.setName("服务详情");
			// selection.save();
			//
			// BkItemSelection itemSelection = new BkItemSelection();
			// itemSelection.setItemId(item.getId());
			// itemSelection.setSelectionId(selection.getId());
			// itemSelection.save();

			renderText("注册成功!");
			try {
				// String content = "恭喜你注册成功,稍候肯定没有工作人员联系您,永别<a
				// href=\"index?shopId=2&amp;itemId=4&amp;selectionId=7&amp;time=22&amp;date=2016-08-15\">11:00</a>";
				// MailSenderInfo maiInfo = MailUtils.defaultSender();
				// maiInfo.setContent(content);
				// maiInfo.setToAddress(email);
				// new MailUtils().send(maiInfo);
			} catch (Exception e) {
				System.out.println("" + email);
			}
		}
	}
}
